package com.tvein.sanguo.event.view
{
	//flash
	import flash.events.Event;
	//pureMVC
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.utilities.fabrication.patterns.mediator.FlashMediator;
	//custom
	import com.tvein.sanguo.event.common.GameConstants;
	import com.tvein.sanguo.event.model.SystemProxy;
	import com.tvein.sanguo.Event;
	import com.tvein.sanguo.swc.event.EventShell;
//
	public class EventMediator extends FlashMediator
	{
		static public const NAME : String = "EventMediator";
		
		public function EventMediator(viewComponent:Object)
		{
			super(NAME, viewComponent);
		}
		
		public function get event() : com.tvein.sanguo.Event
		{
			return viewComponent as com.tvein.sanguo.Event;
		}
		
		//Custom
		private var systemData:SystemProxy;
		public var eventShell:EventShell;
		
		override public function onRegister() : void
		{
			systemData = facade.retrieveProxy(SystemProxy.NAME) as SystemProxy;
			
			eventShell = new EventShell(systemData.config);
			
			event.addChild(eventShell);
			
			eventShell.addEventListener("EventShell", _handleEvents);
		}
		
		private function _handleEvents(evt:Object):void
		{
			switch(evt.cmd[0])
			{
				case "play":
					sendNotification(GameConstants.EVENT_RUN, ["play"]);
					break;
				case "music":
					if (evt.cmd[1] == "mute")
					{
						routeNotification(GameConstants.MODULE_INVOKE, ["-init", ["mute", "on"]], null, GameConstants.MODULE_ZONE + "/*");
					}
					if (evt.cmd[1] == "resume")
					{
						routeNotification(GameConstants.MODULE_INVOKE, ["-init", ["mute", "off"]], null, GameConstants.MODULE_ZONE + "/*");
					}
					break;
				case "btnYes":
					sendNotification(GameConstants.EVENT_RUN, ["action", evt.cmd[1]]);
					break;
				case "btnNo":
					sendNotification(GameConstants.EVENT_RUN, ["action", evt.cmd[1]]);
					break;
			}
		}
	}
}